import { getUserInfoUrl } from "@/command/apiTool";
import ButtonView from "@/components/ButtonView";
import CardView from "@/components/CardView";
import InfoCellGray from "@/components/InfoCellGray";
import ListView from "@/components/ListView";
import Page from "@/components/Page";
import RoundInfo from "@/components/RoundInfo";
import TextView from "@/components/TextView";
import { Button } from "vant";
import { defineComponent, ref } from "vue";
import style from "./index.module.less";
import SpecialistIcon from "@/assets/image/specialistIcon.png";
import { useRouter } from "vue-router";
import { getParamUrl } from "@/command/util";
import { useRequest } from "./requset";
import moment from "moment";
export default defineComponent({
  setup(props, {}) {
    const router = useRouter();
    const userInfo = localStorage.getItem("userInfo") as string;
    const userInfoJSON = JSON.parse(userInfo) as any;
    const { messageList } = useRequest();
    // const timInfo = {
    //   userId: "12345",
    //   to: "54321",
    //   template: "287a53aa61aed3d900d4a9091f69dce0",
    //   appid: "1400804218",
    //   title: "liayyy",
    // };
    // const url = getParamUrl(timInfo);
    const renderItem = (item: any) => {
      let times = moment(item.lastMessage.lastTime * 1000).format("HH:mm");
      if (
        moment(item.lastMessage.lastTime * 1000).format("YYYY-MM-DD") !=
        moment().format("YYYY-MM-DD")
      ) {
        times = moment(item.lastMessage.lastTime * 1000).format("YY/MM/DD");
      }
      return (
        <RoundInfo
          class={"newpage  w-full bg-white p-[15px]"}
          src={
            item.userProfile.avatar ||
            "https://qfile.nongqibang.com/default_icon.png"
          }
          title={item.userProfile.nick}
          text={item.lastMessage.messageForShow}
          badgeNum={item.unreadCount ? item.unreadCount : ""}
          right={() => <span class="text-[#c7c2c1] text-[12px]">{times}</span>}
          onClick={() => {
            // console.log(2222, "http://localhost:3001/#/?" + url);

            // window.location.href = `https://im.ztesa.com.cn/#/?${url}`;
            // router.push("/serviceTim");
            router.push(
              `/serviceTim?userId=${userInfoJSON.phone}&name=${item.userProfile.nick}&to=${item.userProfile.userID}`
            );
          }}
        />
      );
    };
    const renderUserInfo = () => {
      const newData = [
        {
          title: "宁波市天胜吃点农场",
          text: "如果想详细了解，电话联系",
          src: SpecialistIcon,
          time: "11:11",
          badgeNum: 5,
        },
        {
          title: "宁波市天胜吃点农场",
          text: "如果想详细了解，电话联系",
          src: SpecialistIcon,
          time: "10:11",
          badgeNum: 5,
        },
        {
          title: "宁波市天胜吃点农场",
          text: "如果想详细了解，电话联系",
          src: SpecialistIcon,
          time: "22/02/16",
          badgeNum: 26,
        },
        {
          title: "宁波市天胜吃点农场",
          text: "如果想详细了解，电话联系",
          src: SpecialistIcon,
          time: "22/02/16",
        },
      ];
      return (
        <div class={"pb-[65px]"}>
          <ListView
            type="custom"
            data={messageList.value}
            renderItem={renderItem}
            itemHeight={75}
            bottomText={"暂无消息记录"}
            themeStyle="list-bottom-border"
            style={{
              height:
                messageList.value.length > 0
                  ? "calc(100% - 68px)"
                  : "calc(100vh - 68px)",
            }}
          />
        </div>
      );
    };
    return () => {
      return (
        <Page padding={0} class={["overflow-y-auto"]}>
          <div class={[style["index"]]}>{renderUserInfo()}</div>
        </Page>
      );
    };
  },
});
